| Conditions | 10 |
| Paths | 11 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Script.js ➔ ... ➔ ??? often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | |||
| 11 | constructor(params) { |
||
| 12 | |||
| 13 | super(); |
||
| 14 | |||
| 15 | if (params.component && params.component.templateNodes && params.element && |
||
| 16 | params.element[0] && params.element[0].outerHTML) |
||
| 17 | { |
||
| 18 | let script = params.element[0].outerHTML; |
||
| 19 | script = !script ? '' : script |
||
| 20 | .replace(/<x-script/i, '<script') |
||
| 21 | .replace(/<b><\/b><\/x-script>/i, '</script>'); |
||
| 22 | |||
| 23 | if (script) |
||
| 24 | { |
||
| 25 | params.element.text(''); |
||
| 26 | params.element.replaceWith( |
||
| 27 | $(script).text(params.component.templateNodes[0] && |
||
| 28 | params.component.templateNodes[0].nodeValue ? |
||
| 29 | params.component.templateNodes[0].nodeValue : '')); |
||
| 30 | } |
||
| 31 | else |
||
| 32 | { |
||
| 33 | params.element.remove(); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 40 |